﻿using SmartSapce.ServiceLocation;
using SmartSpace.OA;
using SmartSpace.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Workflow;

namespace SmartSpace.WebApp.Modules.OA.Pages
{
    public partial class LeaveRequest_List : SsTemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ILeaveService service = ServiceLocator.Get<ILeaveService>();
                IWorkflowService wfService = ServiceLocator.Get<IWorkflowService>();
                List<ActivityMetadata> activities = wfService.GetActivities("OA.LEAVE");
                _ctlListActivity.DataSource = activities;
                _ctlListActivity.DataBind();
                
                if(activities.Count>0)
                {
                    _ctlListActivity.SelectedIndex = 0;
                    string activityCode = activities[0].Code;
                    PagedResult<LeaveRequest> result = service.GetRequests(this.User.Identity.Name, activityCode, 0, 999);
                    this._ctlList.DataSource = result.Data;
                    this._ctlList.DataBind();
                }

            }
        }

        protected void _ctlListActivity_SelectedIndexChanged(object sender, EventArgs e)
        {
            string activityCode = _ctlListActivity.SelectedValue;

            ILeaveService service = ServiceLocator.Get<ILeaveService>();
            PagedResult<LeaveRequest> result = service.GetRequests(this.User.Identity.Name, activityCode, 0, 999);
            this._ctlList.DataSource = result.Data;
            this._ctlList.DataBind();
        }
    }
}